package com.acme.domain.account;

import com.acme.exceptions.OverDraftLimitExceededException;

public class CheckingAccount extends AbstractAccount {

	private double overdraft;
	String negAmount = "Amount can not be negative";

	public CheckingAccount(final int id, final double amount,
			final double overdraft) {
		super(id, amount);
		this.overdraft = overdraft;
	}

	@Override
	public void withdraw(final double amount)
			throws OverDraftLimitExceededException {
		if (amount < 0) {
			throw new IllegalArgumentException(negAmount);
		}
		if (this.balance - amount >= -overdraft) {
			if (this.balance >= amount) {
				this.balance -= amount;
			}
			overdraft += this.balance - amount;
			this.balance = 0.0;

		} else {
			double need = amount - this.balance - overdraft;
			throw new OverDraftLimitExceededException(need, this.balance,
					overdraft);
		}

	}

	@Override
	public void deposit(final double amount) {
		if (amount > 0) {
			this.balance += amount;
		} else {
			throw new IllegalArgumentException(negAmount);
		}

	}

	public AccountType getAccountType() {
		return AccountType.CHECKING;
	}

	public double getOverdraft() {
		return overdraft;
	}
}
